<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>View Shipping Order| Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <p:panel id="panel" header="View Shipping Orders"> 
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus>

            <h:form prependId="false">    
                <p:dataTable var="shippingOrder" value="#{viewShippingOrderManagerBean.shippingOrder}" 
                             dynamic="true" paginator="true" rows="10" emptyMessage="No Shipping Order Record" selection="#{viewShippingOrderManagerBean.selectedShippingOrder}" onRowSelectUpdate="display">
                    <p:column selectionMode="single"/>

                    <p:column sortBy="#{shippingOrder.id}" filterBy="#{shippingOrder.id}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Shipping Order ID" /> 
                        </f:facet> 
                        <h:outputText value="#{shippingOrder.id}" /> 
                    </p:column> 

                    <p:column sortBy="#{shippingOrder.deliveryOrder.id}" filterBy="#{shippingOrder.deliveryOrder.id}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Delivery ID" /> 
                        </f:facet> 
                        <h:outputText value="#{shippingOrder.deliveryOrder.id}" /> 
                    </p:column>

                    <p:column sortBy="#{shippingOrder.shippingDate}" filterBy="#{shippingOrder.shippingDate}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Shipping Date" /> 
                        </f:facet> 
                        <h:outputText value="#{shippingOrder.shippingDate}" /> 
                    </p:column>

                    <p:column sortBy="#{shippingOrder.deliveryOrder.deliveryState}" filterBy="#{shippingOrder.deliveryOrder.deliveryState}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Delivery State" /> 
                        </f:facet> 
                        <h:outputText value="#{shippingOrder.deliveryOrder.deliveryState}" /> 
                    </p:column>

                    <p:column sortBy="#{shippingOrder.shippingState}" filterBy="#{shippingOrder.shippingState}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Shipping State" /> 
                        </f:facet> 
                        <h:outputText value="#{shippingOrder.shippingState}" /> 
                    </p:column>

                    <f:facet name="footer">  
                        <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="shippingOrderViewDialog.show()"/>
                    </f:facet>

                </p:dataTable>

                <p:dialog header="Shipping Order Detail" widgetVar="shippingOrderViewDialog" width="700" height="700" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="5">
                        <p:fieldset legend="Sale order details">
                        <h:panelGrid columns="2" cellpadding="5">
                            <h:outputText value="Company name:"/>
                            <h:outputText value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.saleOrder.customer.saleLeadName}"/>
                            
                            <h:outputText value="Date requested:"/>
                            <h:outputText value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.saleOrder.saleOrderDate}"/>
                        </h:panelGrid>
                        
                        <p:dataTable var="lineItem" value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.saleOrder.lineItems}" dynamic="true" emptyMessage="No Line Item" >
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Product Type"/>
                                </f:facet>
                                    <h:outputText value="#{lineItem.productPrice.productType}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.lineItemQuantity}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Volume Discount"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.volumeDiscountRate}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Final Price"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.finalPrice}"/>
                            </p:column>
                            
                            <f:facet name="footer">
                                <h:outputText value="Total Price :"/>
                                <h:outputText value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.saleOrder.totalPrice}"/>
                            </f:facet>                            
                        </p:dataTable>
                    </p:fieldset>
                        </h:panelGrid>
                    <br></br>
                    
                    <p:fieldset legend="Delivery order details" id="display2">
                        
                        <h:outputText value="Delivery Order ID:"/>
                        <h:outputText value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.id}"/>
                            
                        <p:dataTable var="productLineItem" value="#{viewShippingOrderManagerBean.selectedShippingOrder.deliveryOrder.pickingOrder.productLineItems}" dynamic="true" emptyMessage="No Product Type" >
                            <p:column sortBy="#{productLineItem.batch.product.productType}">
                            <f:facet name="header">
                                <h:outputText value="Product Type"/>
                            </f:facet>
                                <h:outputText value="#{productLineItem.batch.product.productType}"/>
                        </p:column>

                        <p:column sortBy="#{productLineItem.quantity}">
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{productLineItem.quantity}"/>
                        </p:column>
                        
                        
                        <p:column sortBy="#{productLineItem.batch.id}">
                            <f:facet name="header">
                                <h:outputText value="Batch ID"/>
                            </f:facet>
                            <h:outputText value="#{productLineItem.batch.id}"/>
                        </p:column>

                        <p:column sortBy="#{productLineItem.batch.location}">
                            <f:facet name="header">
                                <h:outputText value="Batch Location"/>
                            </f:facet>
                            <h:outputText value="#{productLineItem.batch.location}"/>
                        </p:column>

                        <p:column sortBy="#{productLineItem.batch.expiryDate}">
                            <f:facet name="header">
                                <h:outputText value="Expiry Date"/>
                            </f:facet>
                            <h:outputText value="#{productLineItem.batch.expiryDate}"/>
                        </p:column>


                    </p:dataTable>
                    </p:fieldset>
                </p:dialog>

            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>
